package com.eairlv.route.client.entity;

import cn.hutool.core.util.StrUtil;
import com.eairlv.route.client.utils.BeanUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author lv
 * @create 2018-07-23 10:17
 * @desc
 **/
@Data
@Builder
@Slf4j
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {

    private int code;

    private String message;

    private T data;

    public static Object failMessage(Class<?> className){
        return failMessage(null, className);
    }

    public static Object failMessage(String message, Class<?> className){
        if (StrUtil.isNotBlank(message)){
            log.warn(message);
        }
        return BeanUtil.copyProperties(Result.builder()
                .code(HttpResult.FAIL.getCode())
                .message(message)
                .build(), className);
    }

}
